package cn.wolfcode.wolf2w.web.controller;


import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.query.DestinationQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/destination")
public class DestinationContrpller {

    @Autowired
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(Model model , @ModelAttribute("qo")DestinationQuery qo){
        Page<Destination> page= destinationService.query(qo);
        //分页数据
        model.addAttribute("page" ,page);
        //面包屑
        List<Destination> list=  destinationService.queryToasts(qo.getParentId());
        model.addAttribute("toasts" ,list);

        return "/destination/list";
    }

    //删除
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){

        destinationService.delete(id);
        return JsonResult.success();
    }
    //文章更新
    @RequestMapping("/updateInfo")
    @ResponseBody
    public Object delete(String id,String info){

        destinationService.Update(id,info);
        return JsonResult.success();
    }

}
